package com.echo.im.storage.offline;


import com.echo.im.common.model.mq.OfflineMsgMqInfo;
import com.echo.im.repository.offline.OfflineMessageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * @author echo
 * @date 2024-08-15
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class StoreOfflineMessageService {

    private final List<OfflineMessageService<OfflineMsgMqInfo>> offlineMessageServiceList;

    public void storeOfflineMessage(OfflineMsgMqInfo offlineMsgMqInfo) {
        for (OfflineMessageService<OfflineMsgMqInfo> offlineMessageService : offlineMessageServiceList){
            if (offlineMessageService.support(offlineMsgMqInfo.getType())){
                offlineMessageService.addOfflineMessage(offlineMsgMqInfo.getUserId(), offlineMsgMqInfo.getMsgId());
                break;
            }
        }
    }
}
